#include <iostream>
#include <queue>
#include <cmath>
using namespace std;
const int N = 2e5 + 10;
bool st[N];
int s[N];
struct node {
	int d;//cha;
	int l, r;
	bool operator<(const node& x) const
	{
		if (d != x.d)return d > x.d;
		else if (l != x.l)return l > x.l;
		else return r > x.r;
	
	}
};
priority_queue<node> heap;
int main()
{
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		char ch;
		cin >> ch;
		if (ch == 'B')s[i] = 1;
	}
	int e[N], pre[N], ne[N];
	for (int i = 1;i <= n;i++)
	{
		cin >> e[i];
		pre[i] = i - 1;
		ne[i] = i + 1;
	}
	pre[1] = ne[n]=0;
	for (int i = 1;i < n;i++)
	{
		if(s[i]!=s[i+1])
		heap.push({ abs(e[i] - e[i + 1]),i,i + 1 });
	}
	vector<node> ret;
	while (heap.size())
	{
		auto t = heap.top();heap.pop();
		int d = t.d, l = t.l, r = t.r;

		if (st[l] || st[r])continue;
		st[l] = true;st[r] = true;
		ne[pre[l]] = ne[r];
		pre[ne[r]] = pre[l];
		ret.push_back({ d, l, r });
		int left = pre[l], right = ne[r];
		if(left&&right&&s[left]!=s[right])
		heap.push({ abs(e[left] - e[right]),left,right });
	}
	cout << ret.size() << endl;
	for (auto&v :ret)
	{
		cout << v.l << " " << v.r << endl;
	}
	return 0;
}